# 字符          数值
# I             1
# V             5
# X             10
# L             50
# C             100
# D             500
# M             1000


def romanToInt(s):
    roman_dic = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}
    length = len(s)
    count, res = 0, 0
    while count <= length - 2:
        if roman_dic[s[count]] >= roman_dic[s[count + 1]]:
            res += roman_dic[s[count]]
        else:
            res -= roman_dic[s[count]]
        count += 1
    return res + roman_dic[s[count]]
